package com.xike.micromemberserver.service.impl;

import com.xike.entiy.ResultBean;
import com.xike.micromemberserver.dao.BookshelfDao;
import com.xike.micromemberserver.entity.Bookshelf;
import com.xike.micromemberserver.service.BookshelfService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Bookshelf)表服务实现类
 *
 * @author makejava
 * @since 2021-04-29 09:34:33
 */
@Service("bookshelfService")
public class BookshelfServiceImpl implements BookshelfService {
    @Resource
    private BookshelfDao bookshelfDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Bookshelf queryById(Integer id) {
        return this.bookshelfDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Bookshelf> queryAllByLimit(int offset, int limit) {
        return this.bookshelfDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param bookshelf 实例对象
     * @return 实例对象
     */
    @Override
    public Bookshelf insert(Bookshelf bookshelf) {
        this.bookshelfDao.insert(bookshelf);
        return bookshelf;
    }

    /**
     * 修改数据
     *
     * @param bookshelf 实例对象
     * @return 实例对象
     */
    @Override
    public Bookshelf update(Bookshelf bookshelf) {
        this.bookshelfDao.update(bookshelf);
        return this.queryById(bookshelf.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public ResultBean deleteById(Integer id) {
        int res=bookshelfDao.deleteById(id);
        return ResultBean.builder().code(200).msg("删除成功").build();
    }

    @Override
    public ResultBean selectByUser(String username) {
        List<Bookshelf> res=bookshelfDao.selectByUser(username);
        return ResultBean.builder().code(200).data(res).build();
    }

    @Override
    public ResultBean insertOne(Bookshelf bookshelf) {
        int res=bookshelfDao.insertOne(bookshelf);
        return ResultBean.builder().code(200).msg("新增成功").build();
    }
}